(function (YuXi) {
	var Updates={};
	var taskQuery={};//任务派遣所需值
	var file=[];
	requestSource();
	requestSort();
	requestPort(); 
	requestClassification();
	Updates.checkFlag={sele:false,pes:false,sort:false};

	var sorFlag=false;
	var fenFlag=false;
	var detailId="";
	var flowId="";
	var goBackUrl="";
	var menuId="";
	var submitUrl="";
	var information={};
	var flag=0;
	Updates.init=function(detailIds,flowIds,goBackUrls,menuIds,submitUrls){
		detailId=detailIds;
		flowId=flowIds;
		goBackUrl=goBackUrls;
		menuId=menuIds;
		submitUrl=submitUrls;
	}


//根据id向后台请求数据详情
Updates.requestDetail=function(id)
{	
	var url="getUserInformationById.do";//向后台请求数据id
	var object={}
	var sourceName;
	var personId;
	var personName;
	var dataid={informationId:id};
	YuXi.util.get(url,dataid,function(data){
		object=data.object;
		sourceName=object.informationSourceNames.split(",");
		personName=object.inputPerSonNames.split(",");
		personId=object.inputPersonID.split(",");
		Allsourcename=object.informationSourceID.split(",");

		AllportName=object.safetyPortId;


		object.informationSourceNames=object.informationSourceNames.substring(0,object.informationSourceNames.length-1);
		YuXi.fenkouSourceUpdate.get(object.informationSourceID,object.safetyPortId);

		
		addSelect(".sele",object.safetyPortNames);
		addSelect(".pes",object.informationClassificationNames);
		addSelect(".sort",object.informationSortNames);
		for(var i=0;i<personName.length;i++){
			if(personName[i]!=""){
					var html="<span class='parsbox'><span  class='glyphicon glyphicon-user' aria-hidden='true' ></span><span class='select-data-user' data-id="+personId[i]+">"+personName[i]+"</span>&nbsp;&nbsp;<span   class='glyphicon glyphicon-remove' aria-hidden='true'></span></span>"
			        $(".label1").append(html);
				
				html= '<li><input type="checkbox"  data-id='+personId[i]+' value='+personName[i]+' name="Check">'+personName[i]+'</li>';
				$("#addRequest").find("ul").append(html);
			}
			
		}
		$(".infoBelong").html(object.prisonName);
		$(".briefing").text(object.informationProfile);//简介
		$(".basic").text(object.standard);//标准
		$(".step").text(object.mesure);//措施
		$(".cont").text(object.informationConternt);//内容
		/***********************12.11***************************/
		$(".userNameIn").html(object.userName);//录入人
		/***********************12.11***************************/
		file=object.appendix;
		if(file==null||file=="[]"){
			;
		}else{
			file=JSON.parse(file);
			var appendix=object.appendix.substring(1,object.appendix.length-1);
			appendix=appendix.split(",");
			YuXi.appendix.get(appendix);
		}
		cancelappend();
	},function(){
		//console.log("数据请求失败");

	})

}//requestDetail
//参与人选择
$("#select-all").on('click',function(){		
		var check=$("input[name='isCheck']");
		$(check).each(function(){
			if(!$(this).is(":checked"))
			  $(this).click();
		});
	})
	$("#select-fan").on('click',function(){
		var check=$("input[name='isCheck']");
		$(check).each(function(){			
			  $(this).click();
		});
	})

//获取全部信息
Updates.getInformation=function(flag){
	var check=[];
    var sourceName=[];
    var personId=[];
    var personName=[];
   
    $("input[name='source']:checked").each(function () {
    	check.push($(this).val());
        sourceName.push($(this).attr("data-na"));
            
     });
    $(".select-data-user").each(function(){
    
		personId.push($(this).attr("data-id"));
		personName.push($(this).html());
		
		
	})
   
	information.id=detailId;
	
	var sourceid="";
	var sourcename="";
	//-----------------------------------------------------10.8
	 sourceid=$("#souceMut").select2('val').join(",")+",";
	 for(var yy=0;yy<$("#souceMut").select2('val').length;yy++)
	 {
	 	var nameyy=$("#souceMut").select2('data')[yy].text;
	 	nameyy=$.trim(nameyy);
	 	sourcename=sourcename+nameyy+",";
	 }
	 //--------------------------------------------------------10.8
	//--------------------------------------
	var sourceArray=sourceid.split(",");
	
	for(var j=0;j<sourceArray.length;j++)
	{
		var currs=YuXi.recursionSource.get(sourceArray[j])+",";
		sourceid+=currs;		
	}
	var arrayunqiue=[];
	arrayunqiue=YuXi.recursionSource.unique(sourceid.split(","));
	sourceid=arrayunqiue.join(",");
//----------------------------------------------
    information.informationSourceID=sourceid;//渠道
    information.informationSourceNames=sourcename;
    //---------------------------------------------------------------------------------10.8
 	information.safetyPortId=$("#fenkMut").select2('val');//分口
	information.safetyPortNames=$.trim($("#fenkMut").select2('data')[0].text);
	//----------------------------------------------------------------------------------10.8
    information.informationClassificationId=parseInt($(".pes option:selected").val());//分级
    information.informationClassificationNames=($(".pes option:selected").html());
    information.informationSortId=($(".sort option:selected").val());//分类
    information.informationSortNames=($(".sort option:selected").html());
    information.mesure=$(".step").text();//措施
    //information.standard=$(".basic").text();//标准
    information.informationProfile=$(".briefing").text();//简介
    information.informationConternt=$(".cont").text();//内容


    information.inputPersonID=personId.join(",");//参与人
    information.inputPerSonNames=personName.join(",");
    information.appendix=JSON.stringify(file);
/*    console.log(JSON.stringify(information));*/
	
	  //任务派遣所需的信息
	if(menuId==13||menuId==15){
		
		information.zeRenRemark=$("#note").text();//责任人备注
		var overTime;
	    var timeStr=$("input[id='overTime']").attr('placeholder');
	    if($("#overTime").val()==null||$("#overTime").val()==""||$("#overTime").val()==timeStr){
	    	 overTime="2080-12-31";
	    }else{
	    	 overTime=$("#overTime").val();
	    }
	    

		taskQuery.time=new Date(Date.parse(overTime.replace(/-/g, "/")));
		taskQuery.idStr="";
		taskQuery.nameStr="";
		var span=$(".taskPeople").children("span");
		for(var i=0;i<span.length;i++){
			var name=span.eq(i).children("span").eq(1).html();
			var id=span.eq(i).children("span").eq(1).attr("data-id")
			taskQuery.idStr=id+","+taskQuery.idStr;
			taskQuery.nameStr=name+","+taskQuery.nameStr;
		}
		taskQuery.note=$("#note").text();
	    //return false;
		if(span.length==0){
			myTool.alert({
				title:"提示",
				context:"请选择责任人"
			});
			return false;
		}
		if(!isNull(information.mesure)){
	    	myTool.alert({		
				title:"提示",
				context:"请录入信息措施！",
				isMask:true,
				callback:function(){
					}
			});
			return false;
		}
		if(menuId==13){//任务派遣
		    myTool.alert({		
				title:"提示",
				context:"是否确认对信息进行任务派遣?",
				isMask:true,
				callback:function(){
					YuXi.Updates.requestUpdate(information,0);
					
				}
			});
		}else{
			myTool.alert({		
				title:"提示",
				context:"是否确认对信息进行即时任务派遣?",
				isMask:true,
				callback:function(){
					YuXi.Updates.requestUpdate(information,0);
					
				}
			});
		}
		return;
	}

   /*10-7*/
   if(!isNull(information.informationSourceID)){
    	myTool.alert({		
			title:"提示",
			context:"请确定二级渠道是否正确。再次提交",
			isMask:true,
			callback:function(){
				}
			});

    	YuXi.scrollbar.scroll("#resour");
    	return false;
    }
  	if(flowId==5){
	    if(!isNull(information.mesure)){
	    	myTool.alert({		
				title:"提示",
				context:"请录入信息措施！",
				isMask:true,
				callback:function(){
					}
			});
			return false;
		}
	}
    if(!isNull(information.safetyPortId)){
    	myTool.alert({		
			title:"提示",
			context:"请确定二级分口是否正确。再次提交",
			isMask:true,
			callback:function(){
				}
			});

    	YuXi.scrollbar.scroll("#treeTable2");
    	return false;
    }

    /*10-7*/
    if(!isNull(information.informationProfile)){
    	myTool.alert({		
			title:"提示",
			context:"失败,简介不能为空。",
			isMask:true,
			callback:function(){
				}
			});

    	YuXi.scrollbar.scroll("#resour");
    	return false;
    }
    if(!isNull(information.informationConternt)){
    	myTool.alert({		
			title:"提示",
			context:"失败,内容不能为空。",
			isMask:true,
			callback:function(){
				}
			});

    	
    	return false;
    }


		if(!isNull($(".remark").text())&&menuId==17){
			myTool.alert({		
					title:"提示",
					context:"请录入任务完成情况！",
					isMask:true,
					callback:function(){}
				});
			return false;
		}

   if(flag==0)
   {
   	information.flag=0;
   	if(menuId==4){
   	 myTool.alert({		
		title:"提示",
		context:"是否确认对信息的操作?",
		isMask:true,
		callback:function(){
			if($(".operation option:selected").html()=="通过"){
				
				YuXi.Updates.requestUpdate(information,0);
			}else if($(".operation option:selected").html()=="退回"){
				refuseInfo();
			}else {
				Updates.finishInfo();
			}
			
			
		}
	});

   	 }else if(menuId==7||menuId==9){
   	 	myTool.alert({		
		title:"提示",
		context:"是否确认对信息的操作?",
		isMask:true,
		callback:function(){
			if($(".operation option:selected").html()=="通过"){
				
				YuXi.Updates.requestUpdate(information,0);
			}else if($(".operation option:selected").html()=="即时任务派遣"){
				YuXi.Updates.requestUpdate(information,0);
			}else if($(".operation option:selected").html()=="退回"){
				infoBackToFirstCheck();
			}else if($(".operation option:selected").val()=="changeInfoSource"){
				YuXi.Updates.requestUpdate(information,0);
			}else{
				Updates.finishInfo();
			}
			
			
		}
	});
   	 }else{
   	 	myTool.alert({		
				title:"提示",
				context:"确认提交?",
				isMask:true,
				callback:function(){
					YuXi.Updates.requestUpdate(information,0);
					
				}
			});
   	 }
   	 
   }else{
   		information.flag=1;
   		
	   	myTool.alert({		
			title:"提示",
			context:"是否确认保存信息?",
			isMask:true,
			callback:function(){			
					
					YuXi.Updates.requestUpdate(information,1);
			}
		});
		
   }
	 
}//getInformation
//确认过后返回
Updates.goBack=function(){
	window.location.href=goBackUrl+"?menuId="+menuId;
}
//修改分口，分类，分级，标准，措施
Updates.requestUpdate=function(information,flag)
{	var  flowName="";
	if(flowId==1){
		flowName="InfoManage";
	}
	if(flowId==2){
		flowName="FirstCheck";
	}
	if(flowId==3){
		flowName="ReCheck";
	}
	if(flowId==4){
		flowName="Check";
	}
	if(flowId==5){
		flowName="InfoResearch";
	}
	if(flowId==6){
		flowName="TaskDispatch";
	}
	if(flowId==7){
		flowName="CurTaskDispatch";
	}



	if(flowName==""){
		inputCondition();
		return;
	}

	var url=flowName+"/userUpdataInformation.do";//修改的地址;
	YuXi.util.post(url,information,function(data){
	
		if(data.status)
		{ 
			var remark=$(".remark").text();
		   var operation= $(".operation option:selected").html();

		   //研判
		   if(flowId==5){

		   		/*var url="InfoResearch/userUpdataInformation.do";//修改的地址
			YuXi.util.get(url,information,function(data){
			if(data.status)
			{	
				myTool.alert({		
					title:"提示",
					context:data.msg,
					isMask:true,
					callback:function(){
						YuXi.Updates.goBack();
					}
				});
				YuXi.Updates.goBack();
			}
			else
			{
				myTool.alert({		
					title:"提示",
					context:"操作失败",
					isMask:true,
					callback:function(){
						YuXi.Updates.goBack();
					}
				});
				
			}
		},function(){
	
		})*/
		  		
		   		myTool.alert({		
					title:"提示",
					context:data.msg,
					isMask:true,
					callback:function(){
						
						return;
						YuXi.Updates.goBack();
					}
				});
				YuXi.Updates.goBack();
		   }else if(menuId==13||menuId==15){
		   		var url="";
		   		if(menuId==13){
		   			url="TaskDispatchFilter/taskDispatchModi.do";
		   		}else{
		   			url="CurTaskDispatchFilter/curTaskDispatchModi.do"
		   		}

		   		taskDispatch(taskQuery.time,taskQuery.note,taskQuery.idStr,taskQuery.nameStr,url);

		   }else if(flag==0)
		   {

		   	if(flowId==1||flowId==2){
		   		var url="SubToFirstCheck.do";
		
				YuXi.util.get(url, {infoId: detailId}, function(data) {
					if(data.status){
						myTool.alert({		
							title:"提示",
							context:"提交信息成功。",
							isMask:true,
							callback:function(){
								YuXi.Updates.goBack();
							}
						});
					}
				},function(){
					
				});
				return;
		   	}
		   	YuXi.util.post(submitUrl,{infoId:detailId,remark:remark,operation:operation},function(data){
				 myTool.alert({		
						title:"提示",
						context:data.msg,
						isMask:false,
						callback:function(){
							YuXi.Updates.goBack();
						}
				  })
				  YuXi.Updates.goBack();

			  });


		   	if($(".operation option:selected").html()=="通过"){
					YuXi.util.post(submitUrl,{infoId:detailId,remark:remark,operation:operation},function(data){
						 myTool.alert({		
								title:"提示",
								context:data.msg,
								isMask:false,
								callback:function(){
									YuXi.Updates.goBack();
								}
						  })
						  YuXi.Updates.goBack();

					  });
					}else if($(".operation option:selected").html()=="即时任务派遣"){
							task();
					}else{
						checkSubWay();
					} 


		   }
		   else
		   {
		   	myTool.alert({		
						title:"提示",
						context:"修改信息成功",
						isMask:false,
						callback:function(){
							YuXi.Updates.goBack();
						}
				  })
		   }
			
		}
		else
		{
			myTool.alert({		
				title:"提示",
				context:"提交信息失败！",
				isMask:false,
				
			});
		}
	},function(){
		myTool.alert({		
			title:"提示",
			context:"发生未知错误！",
			isMask:true,
			callback:function(){}
		});
	})
}//requestUpdate

/*判断输入合法性*/
function isNull(str){
	if(str==null||str==""){
		return false;
	}else{
		return true;
	}
}//isNull

//删除附件
	function cancelappend()
	{
		
		$(".appendixcancel span").click(function(){file=[];
			var dataurl=$(this).attr("data-url");
			$(this).parent(".appendixcancel").remove();
			$("#valAppendix ").find(".appendixcancel").each(function(){
			
				file.push($(this).find("span").attr("data-url"));
			})
		
		})
	}//cancelappend
	//向后台提交附件，返回地址
	 Updates.modifyFileup=function(){
			$("#loading").show();
			 $("#loadOk").hide();
	    $.ajaxFileUpload({
	        type:"post",
	        secureuri:false,
	        dataType:"json",      
	        url:"/yuxi/userFileUp.do",
	        fileElementId:"upfile-haoping",
	        success:function(data,status){

	        	var appendix=JSON.stringify(data.addressList);
	        	
	        	try{
	        		if(file==null){
	        		file=JSON.parse(appendix);
	        		
	        	}else{

	        		appendix= appendix.substring(1,appendix.length-1).split(",");
	        		for(var i=0;i<appendix.length;i++){
		        		

	        				file.push(appendix[i].substring(1,appendix[i].length-1));

		        	}
		        	
	        	}

	        	}catch(e){



	        	}
	        	
	        	
	        	$("#fileValue").remove();
	        	var html='<input id="upfile-haoping" name="files" multiple="multiple" style="position:absolute; right:0; top:0; font-size:100px; opacity:0; filter:alpha(opacity=0);" type="file" value="浏览" />';
	        	$("#fileUp").append(html);
	        	$("#loading").hide();
	        	$("#loadOk").show();

	        },
	        error:function(data){
	        	
	          
	        } 
	        
	      });
	    }//modifyFileup
Updates.getInformationFlow=function(id){
		var url="getInformationFlowByInfoId.do";
		var infoId={infoId:id};
		var object={};
		YuXi.util.get(url,infoId,function(data){
			if(data.status){
				object=data.object;
				var flow;
				
				for (var i = 0; i < object.length; i++) {
					if(object[i].lastFlowId==1){
						flow="信息管理";
					}
					if(object[i].lastFlowId==3){
						flow="复核";
					}
					if(object[i].lastFlowId==2){
						flow="初审";
					}
					if(object[i].lastFlowId==4){
						flow="审核";
					}
					var time = YuXi.getTime.get(object[i].createTime);
					
					if(object[i].remark==undefined){
						object[i].remark="";
					}
					var html = "<tr ><td style='border:none;'>" + object[i].userName + "</td>" +
					
					"<td style='border:none;'>" +time  + "</td>" +
					"<td style='border:none;'>" + object[i].operation + "</td>" +
					"<td style='border:none;'>" + object[i].remark + "</td>" +
					
					"<td style='border:none;'>" +flow  + "</td>" +
 					"</tr>";
					$("#tbody").append(html);
				}
			}
		},function(){
			
		});
	}//getInformationFlow


//结束信息
Updates.finishInfo=function (){
	var remark = $(".remark").text();	
	YuXi.util.get("subToInfoFinsh.do",{infoId:detailId,remark:remark},function(data){
		 myTool.alert({
			 title:data.subType,
			 context:data.msg,
			 isMask:false,
				callback:function(){
					YuXi.Updates.goBack();
				}
		 });
		 YuXi.Updates.goBack();	 
	 });
}
//退回信息
function refuseInfo(){
	var remark = $(".remark").text();
	var operation= $(".operation option:selected").html();
	YuXi.util.get("FirstCheckFilter/ReToInfoMannger.do",{infoId:detailId,remark:remark,operation:operation},function(data){
		 myTool.alert({
			 title:data.subType,
			 context:data.msg,
			 isMask:false,
				callback:function(){
					YuXi.Updates.goBack();
				}
		 });
		 YuXi.Updates.goBack();	 
	 });
}

//退回信息到初审
function infoBackToFirstCheck(){
	
	var operation = $(".operation option:selected").html();
	YuXi.util.get("reCheckToFirstCheck.do",{infoId:detailId,remark:$(".remark").val(),operation:operation},function(data){
		 myTool.alert({
			 title:data.subType,
			 context:data.msg,
			 isMask:false,
				callback:function(){
					YuXi.Updates.goBack();	 
				}
		 });
//		 
	 });
}

 //即时任务派遣
function task(){
		var url="TaskResearchFilter/SubToCurTaskDispatch.do";
		YuXi.util.get(url,{infoId:detailId,remark:$(".remark").text()},function(data){
			if(data.status){
				myTool.alert({
					 title:"提示",
					 context:"即时任务派遣成功",
					 isMask:false,
					 callback:function(){
							
						}
				 });
			YuXi.Updates.goBack();	 
			}
			else{
				myTool.alert({
					 title:"提示",
					 context:"即时任务派遣失败",
					 isMask:false,
					 callback:function(){
						
						}
				 });
			}
		})
	}
//任务派遣
	function taskDispatch(time,note,idStr,nameStr,url){		
		
		var args={informationId:detailId,overTime:time.getTime(),remark:note,personLiableId:idStr,perSonLiableName:nameStr};
		YuXi.util.post(url,args,function(data){
			if(data.status){
				if(menuId==13){
					myTool.alert({		
						title:"提示",
						context:"任务派遣成功",
						isMask:true,
						
					});
				}else{
					myTool.alert({		
						title:"提示",
						context:"即时任务派遣成功",
						isMask:true,
						
					});
				}
				setTimeout(function(){
					YuXi.Updates.goBack();
				},1000);
			}
			else{
				myTool.alert({		
					title:"提示",
					context:"发生未知错误2",
					isMask:true,
					callback:function(){}
				});
			}
		})
	}
	//没有flowId,直接提交
	function inputCondition(){
		if(menuId==18){//信息点评
			var id=detailId;
			 var qualityLvId=$("input[name='infoLv']:checked").val();
			 var qualityLvName=$("input[name='infoLv']:checked").next().html();

			 if(qualityLvId=="" || qualityLvId==undefined)
			 {
			 	myTool.alert({		
					title:"提示",
					context:"请选择录入点评",
					isMask:true,
					callback:function(){}
				});
			 	 return false;
			 }
			 var taskLv=$("input[name='taskLv']:checked").val();
			 var taskLvName=$("input[name='taskLv']:checked").next().html();
			 if(flag==1)
			 {
			 	if(taskLv==undefined)
				{
			 		
			 		myTool.alert({		
					title:"提示",
					context:"请选择完成情况点评",
					isMask:true,
					callback:function(){}
					});
			 	 	return false;
			 	}
			 	var  completeText =$("#complete-text").val();
				 if(completeText==$("#complete-text").attr("placeholder") || completeText=="")
				 {
				 	 myTool.alert({		
						title:"提示",
						context:"请输入完成情况意见!",
						isMask:true,
						callback:function(){}
					});
				 	 return false;
				 }
			 }
			 else
			 {
			 	taskLvName="0";
			 	taskLv="0";
			 }			 
			 var text=$("#commit-text").val();
			 if(text==$("#commit-text").attr("placeholder") || text=="")
			 {
			 	 myTool.alert({		
					title:"提示",
					context:"请输入录入和收集意见!",
					isMask:true,
					callback:function(){}
				});
			 	 return false;
			 }
			 YuXi.util.get("CommentFilter/getInfoTogether.do",{informationId:id,text:text,qualityLvId:qualityLvId,taskLvId:taskLv,qualityLvName:qualityLvName,taskLvName:taskLvName,completeText:completeText },function(data){
				  $("#modal-input-task-finsh-context").modal("hide");	 
				  myTool.alert({
					 title:"提示",
					 context:data.msg
				 });
				 if(data.status){
						YuXi.Updates.goBack();	
				 }
				  
			  },function(){
				  myTool.alert({
						 title:"提示",
						 context:"未知错误1"
					 });
			  });
			 return;
		}


		var context=$(".remark").text();
		
		YuXi.util.get(submitUrl,{inforId:detailId,taskId:flowId,context:context},function(data){
			  $("#modal-input-task-finsh-context").modal("hide");	 
			  myTool.alert({
				 title:"提示",
				 context:data.msg
			 });
			  if(data.status){
					YuXi.Updates.goBack();	
			  }
		  },function(){
			  myTool.alert({
					 title:"提示",
					 context:"未知错误2"
				 });
		  });
	}



function checkSubWay(){
		var t=$(".operation option:selected");
		var targetId=t.attr("data-id");
		var targetName=t.attr("data-name");
		var targetType=t.attr("data-type");			
		var remark=$(".remark").val();
		var data={targetValue:targetType,infoId:detailId,targetPrison:targetId,targetName:targetName,remark:remark};
		if(targetType=="PrisonArea"){
			subToPrisonArea("prisonToPrisonArea.do",data);
		}else{
			subToPrisonArea("prisonAreaToPrison.do",data);
		}
	}	
	function subToPrisonArea(url,data){
		YuXi.util.post(url,data,function(data){
			try{
				myTool.alert({		
					title:data.subType,
					context:data.msg,
					isMask:false					
				});
				YuXi.Updates.goBack();	
			}catch(e){
				myTool.alert({		
					title:"提示",
					context:"未知错误3",
					isMask:false				
				});
			}
		});
	}
/***************************************8888888888888888888888888888888888888888888888888888888888********请求渠道、分口等*/
//渠道
function requestSource()
{	
	var url="getAllInfomationSource.do";//渠道地址
	var data={};
	var object={};
	var superId1=[];//第一层id
	YuXi.util.getAsynCache(url,"null",function(data){
		object=data.object;
		
	xxx(object,"#treeTable1");		
	},function(){});//请求数据

}
//向后台请求分级信息
function requestClassification()
{	
	var url="getAllInformationClassification.do";//分级地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分口信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".pes").append(html);
		}
		Updates.checkFlag.pes=true;
	},function(){
		
	});//请求数据
	
}
//向后台请求分口信息
function requestPort()
{	var url="getAllInformationPort.do";//分口地址
	var data={};
	var object={};
	data=YuXi.util.getAsynCache(url,null,function(data){
		object=data.object;		
			xxx(object,"#treeTable2");
		
	},function(){});//请求数据
	
}
//向后台请求分类信息
function requestSort()
{
	var url="getAllInfomationSort.do";//分类地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分类信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".sort").append(html);
		}
		Updates.checkFlag.sort=true;
	},function(){
		
	});//请求数据
	
}

//向后台请求渠道信息
	//所有数据，和上一层id
	var childer2=[];  
	var childer=[];  
	function xxx(object,className){
		var type="";
		var name="";
		var flag="";
		if(className=="#treeTable1")
		{
			type="checkbox";
			name="sourceCheck";
			flag="name";
		}
		else
		{
			type="radio";
			name="safePort";
			flag="portName";
		}
		var a=[];
		var flag=0;
			var html="";
		var flaga={};
		
		function treeMenu(a){
		    this.tree=a||[];
		    this.groups={};
		};
		treeMenu.prototype={
		    init:function(superId){
		  
		        this.group();
		        return this.getDom(this.groups[superId]);
		    },
		    group:function(){
		    
		        for(var i=0;i<this.tree.length;i++){
		            if(this.groups[this.tree[i].superId]){
		                this.groups[this.tree[i].superId].push(this.tree[i]);
		            }else{
		                this.groups[this.tree[i].superId]=[];
		                this.groups[this.tree[i].superId].push(this.tree[i]);
		            }
		        }

		    },

		    getDom:function(a){
		    	
		    	
		        if(!a){return ''}
		       flag=0;
		        var html="";
		    
		    	if(a[0].superId==0)
		    	{
		    			/*$scope.sorce=a;//第一层结构
		    			//console.log($scope.sorce);*/
		    			for(var i=0;i<a.length;i++)
		    			{
		    				
		    				if(className=="#treeTable2")
		    				{
		    					html='<tr isChange=false id="'+a[i].id+'"   hasChild="hasChild" data-superid="'+a[i].superId+'" style="color:black;" ><td class="bianhao">'+(i+1)+'</td><td>'+a[i].portName+'</td><td><input data-name='+a[i].portName+' data-id='+a[i].id+' type='+type+' name='+name+'></td></tr>\n';		
		    				}
		    				else
		    				{
		    					html='<tr isChange=false id="'+a[i].id+'"   hasChild="hasChild" data-superid="'+a[i].superId+'" style="color:black;" ><td class="bianhao">'+(i+1)+'</td><td>'+a[i].name+'</td><td><input data-name='+a[i].name+' data-id='+a[i].id+' type='+type+' name='+name+'></td></tr>\n';		

		    				}
		    				$(className).append(html);
		    				
		    			}
		    			
		    			flag=1;
		    	}
		    	////console.log("aa"+JSON.stringify(a));
		    	if(flag==0)
		    	{
		    			var length=a.length;
		    			var superid=0;
		    			for(var i=0;i<length;i++)
		    			{	
		    				superid=a[i].superId;
		    				if(isChilde(a[i].id,object))
		    				{ 
		    					
		    					if(className=="#treeTable2")
		    					{

		    					html+='<tr isChange=false id="'+a[i].id+'" hasChild="hasChild" pId="'+a[i].superId+'"   data-superid="'+a[i].superId+'" style="color:black;" ><td class="bianhao">'+(i+1)+'</td><td>'+a[i].portName+'</td><td><input data-name='+a[i].portName+' data-id='+a[i].id+' type='+type+' name='+name+'></td> </tr>\n';		
		    					}
		    					else
		    					{
		    						html+='<tr isChange=false id="'+a[i].id+'" hasChild="hasChild" pId="'+a[i].superId+'"   data-superid="'+a[i].superId+'" style="color:black;" ><td class="bianhao">'+(i+1)+'</td><td>'+a[i].name+'</td><td><input data-name='+a[i].name+' data-id='+a[i].id+' type='+type+' name='+name+'></td> </tr>\n';		
		    					}

		    				}  
		    				else
		    				{  			
		    					if(className=="#treeTable2")
		    					{
		    							html+='<tr isChange=false id="'+a[i].id+'" pId="'+a[i].superId+'"   data-superid="'+a[i].superId+'" style="color:black;" ><td class="bianhao">'+(i+1)+'</td><td>'+a[i].portName+'</td><td><input data-name='+a[i].portName+' data-id='+a[i].id+' type='+type+' name='+name+'></td></tr>\n';		
		    				
		    					}
		    					else
		    					{
		    						html+='<tr isChange=false id="'+a[i].id+'" pId="'+a[i].superId+'"   data-superid="'+a[i].superId+'" style="color:black;" ><td class="bianhao">'+(i+1)+'</td><td>'+a[i].name+'</td><td><input data-name='+a[i].name+' data-id='+a[i].id+' type='+type+' name='+name+'></td></tr>\n';		
		    				
		    					}
		    				}
		    				
		    				
		    				    
		    			}
		    				if(className=="#treeTable1")
		    				{
		    					childer.push({superid:superid,html:html});
		    				}
		    				else
		    				{
		    					childer2.push({superid:superid,html:html});
		    				}

		    			
		    		
		    		
		    			
		    	}
		    	 
		        for(var i=0;i<a.length;i++)
		        {
		           this.getDom(this.groups[a[i].id]);

		        }

	        /*html+='</optgroup>\n';*/

	       /* $("#"+id).append(html);*/
	        return html;
	    }
	   

	}
 var html=new treeMenu(object).init(0);
option(className);
	if(className=="#treeTable2")
	{
		fenFlag=true;
	}
	else
	{
		sorFlag=true;
	}
}

//判断是否有子节点
function isChilde(id,object)
{
	for(var i=0;i<object.length;i++)
	{
		if(object[i].superId==id)
		{
			return true;
		}
	}
	return false;
}
	function option(className)
	{			
			var option = {
	                theme:'vsStyle',
	              
	                beforeExpand : function($treeTable, id) {

	            	var html="";
	                    //判断id是否已经有了孩子节点，如果有了就不再加载，这样就可以起到缓存的作用
	                    if ($('.' + id, $treeTable).length) { return; }
	            
	                   var index=$(className).find("tr").eq(id).attr("id");
	                   if(className=="#treeTable2")
		    			{
		                   for(var i=0;i<childer2.length;i++)
		                   {
		                   	if(id==childer2[i].superid)
		                   	{
		                   		html=childer2[i].html;
		                   	}
		                   }
		                 }
		                 else
		                 {
		                 	 for(var i=0;i<childer.length;i++)
		                   	{
		                   		if(id==childer[i].superid)
		                   		{
		                   			html=childer[i].html;
		                   		}
		                  	 }
		                 }
	                
	                     $treeTable.addChilds(html);

	                     $("input[name='sourceCheck']").each(function(){
					
							for(var i=0;i<Allsourcename.length;i++){
								
								if($(this).attr("data-id")==Allsourcename[i]){
									
									$(this).attr("checked","checked");
									break;
								}
							}
							
						});
	                     $("input[name='safePort']").each(function(){

								if($(this).attr("data-id")==AllportName){
									
									$(this).attr("checked","checked");
									
							}
							
						})
						
					},
					 onSelect : function($treeTable, id) {
	                    window.console && console.log('onSelect:' + id);
	                    
	                }


		}	
	
		$(className).treeTable(option);
	}


var x=1;	//向后台请求渠道信息
function space(superid,object)
{

	if(superid==0)
	{

		return 0;
	}
	for(var i=0;i<object.length;i++)
	{
		if(object[i].id==superid)
		{
			
			x=space(object[i].superId,object);
			
		}
	}
	return x+1;

}

var fff={sele:true,sort:false,pes:false};
function addSelect(className,value){
	var length=className.length;
	
	var newname=className.substring(1,length);
	var time=setInterval(function(){
		if(fff.sele==true && fff.sort==true && fff.pes==true)
		{

			clearInterval(time);
		}
		if(Updates.checkFlag[newname]==true)
		{
			$(className+" option").each(function(){
			if($(this).html()==value){
				$(this).attr("selected","selected");

				//--------------------------------------------------10.8
				 if(className==".pes")
				{
					$(".select2-selection__rendered").eq(2).attr("title",value);
					$(".select2-selection__rendered").eq(2).html(value);
				}
				else
				{
					$(".select2-selection__rendered").eq(3).attr("title",value);
					$(".select2-selection__rendered").eq(3).html(value);
				}
				//-----------------------------------------------------10.8
				fff[newname]=true;
			}
			});
		}
		
	},50);
	
}
/***********************************************请求渠道、分口等*/

	YuXi.Updates=Updates;
})(window.YuXi);